#define BLEND_HARDLIGHT
#define BLEND_NORMAL
#include "res/shaders/BlendMode.frag"

float spread = 0.4;
const float amplitude = 0.1;

vec2 shift(vec2 pos){
    return vec2( sin((pos.y * 2.0 - 1.0) * 6.283 * ( 2.0)) / 32.0,0.0);
}
void mainImage( out vec4 fragColor, in vec2 fragCoord )
{    
    vec2 uv = (fragCoord.xy / iResolution.xy);
    
    vec4 cameraColor = texture2D(iChannel0, uv);
    vec4 maskColor = texture2D(iChannel1, uv);
    vec4 cam2 = texture2D(iChannel2, uv);
    vec4 headMaskColor = texture2D(iChannel3, uv);

    vec4 bgColor = vec4(0.0, 0.0, 0.0, 1.0);
    vec4 lineColor = vec4(0.0, 0.0, 0.0, 1.0);


    vec4 sum = headMaskColor;
    vec2 step = spread / iResolution;
    for(int y = -3; y <= 3; y++){
        for(int x = -3; x <= 3; x++){
          vec4 color = texture(iChannel3, uv + vec2(x, y) * step);
          sum = max(color, sum);
        }
    }


    // blendNormal(baseColor, blendColor, false);

    float lineAlpha = 0.0;
    if (sum.r > 0.3)
    {
      lineAlpha = 1.0;
    }
    float headshootAlpha = 1.0;
    if (headMaskColor.r > 0.3)
    {
      headshootAlpha = 0.0;
    }
    bgColor = blendNormal(bgColor, vec4(lineColor.rgb, lineAlpha), false);
    fragColor = blendNormal(bgColor, vec4(cameraColor.rgb, headshootAlpha), false);
    // fragColor=blendNormal(cam2,fragColor,false);
} 
